// pagesProperty/pages/asset/borrow/index.js
var app = getApp(), fetchApi = require("../../../../utils/httpPost.js"),
formatTime = require("../../../../component/common.js");
import Toast from '../../../../component/vant/toast/toast';
import Dialog from '../../../../component/vant/dialog/dialog';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    assetId:0,
    isLoading: true,
    is_estate_user:0,
    assetInfo:{},
    lastCheck:{},
    isScan:0,
    from:'click', //click - 从前端点击进来的  scan - 从扫码过来的
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log('borrow', options);
    if (options.q) {
      console.log('11111111');
        var q = decodeURIComponent(options.q) // 获取到二维码原始链接内容
        q = "?" + q.split("?")[1];
        this.data.query = q;
        console.log('q', q)
        options = common_Js.getQueryVariable(q);
        this.data.isScan = 1;
        this.setData({
          isScan: 1,
        })
    }
    if(options.from){
      this.setData({
        from: options.from,
      })
    }
    if(options.id){
      this.data.assetId = options.id;
    }
    this.onHttpInit();
  },  
  onHttpInit: function () {
    var that = this;
    fetchApi.httpPost('/estate/asset/detail', {
      asset_id: that.data.assetId,
      op_type: 1,
    }, function (res) {
      console.log("获取资产信息", res)
      if (res.data.code == 0) {
        that.setData({
          hasData: true,
          is_estate_user: res.data.data.is_estate_user,
          assetInfo: res.data.data.asset,
          lastCheck: res.data.data.lastCheck,
        })
      }else{
        Toast.fail(res.data.msg)
      }
      // complete
      wx.hideNavigationBarLoading() //完成停止加载
      wx.stopPullDownRefresh() //停止下拉刷新
      that.setData({ netWork: true,loading: true,  isLoading: false, })
    }, function () {
      that.setData({ netWork: false, hasData: false,loading: true,  isLoading: false, })
    })
  },
  goCheck(e){
    console.log('111')
    wx.navigateTo({
      url: './add/index?id=' + this.data.assetId,
    })
  },
  goRecord(e){
    console.log('222')
    wx.navigateTo({
      url: './record/index?id=' + this.data.assetId,
    })
  },
})